package com.xmall.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmall.auth.dao.SysResourceMapper;
import com.xmall.auth.entity.SysResource;
import com.xmall.auth.service.ISysResourceService;
import com.xmall.common.config.PlatformContant;
import com.xmall.common.config.PojoUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 后台资源表 服务实现类
 * </p>
 *
 * @author liuzh
 * @since 2020-06-14
 */
@Service
public class SysResourceServiceImpl extends ServiceImpl<SysResourceMapper, SysResource> implements ISysResourceService {
    @Autowired
    SysResourceMapper sysResourceMapper;

    @Override
    public boolean saveSysResource(SysResource sysResource) {
        PojoUtils.setSysProperties(sysResource, PlatformContant.OpType.insert);
        return save(sysResource);
    }

    @Override
    public boolean updateSysResource(Long id, SysResource sysResource) {
        SysResource oldSysResource = getById(id);
        BeanUtils.copyProperties(sysResource, oldSysResource);
        PojoUtils.setSysProperties(oldSysResource, PlatformContant.OpType.update);
        boolean update = update(
                oldSysResource,
                new QueryWrapper<SysResource>()
                        .lambda().eq(SysResource::getId, id)
        );
        return update;
    }

    @Override
    public boolean deleteSysResource(Long id) {
        boolean b = removeById(id);
        return b;
    }

    @Override
    public SysResource getSysResource(Long id) {
        SysResource sysResource = getById(id);
        return sysResource;
    }
}
